package o;

import com.google.android.exoplayer2.extractor.ts.TsPayloadReader;
import com.google.android.exoplayer2.extractor.ts.TsPayloadReader.a;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;

public final class ago implements TsPayloadReader {
    private boolean ʻ;
    private final agq ˊ;
    private final anc ˋ = new anc(32);
    private int ˎ;
    private int ˏ;
    private boolean ॱ;

    public ago(agq o_agq) {
        this.ˊ = o_agq;
    }

    public void ˎ(anq o_anq, ady o_ady, a aVar) {
        this.ˊ.ˊ(o_anq, o_ady, aVar);
        this.ʻ = true;
    }

    public void ˏ() {
        this.ʻ = true;
    }

    public void ॱ(anc o_anc, int i) {
        int ʽ;
        boolean z = (i & 1) != 0;
        if (z) {
            ʽ = o_anc.ʽ() + o_anc.ˋ();
        } else {
            ʽ = -1;
        }
        if (this.ʻ) {
            if (z) {
                this.ʻ = false;
                o_anc.ˋ(ʽ);
                this.ˏ = 0;
            } else {
                return;
            }
        }
        while (o_anc.ˊ() > 0) {
            if (this.ˏ < 3) {
                if (this.ˏ == 0) {
                    ʽ = o_anc.ʽ();
                    o_anc.ˋ(o_anc.ˋ() - 1);
                    if (ʽ == 255) {
                        this.ʻ = true;
                        return;
                    }
                }
                ʽ = Math.min(o_anc.ˊ(), 3 - this.ˏ);
                o_anc.ˎ(this.ˋ.ˏ, this.ˏ, ʽ);
                this.ˏ = ʽ + this.ˏ;
                if (this.ˏ == 3) {
                    this.ˋ.ˏ(3);
                    this.ˋ.ˎ(1);
                    int ʽ2 = this.ˋ.ʽ();
                    int ʽ3 = this.ˋ.ʽ();
                    this.ॱ = (ʽ2 & DnsConfig.MAX_CACHE_ENTRIES) != 0;
                    this.ˎ = (((ʽ2 & 15) << 8) | ʽ3) + 3;
                    if (this.ˋ.ˎ() < this.ˎ) {
                        Object obj = this.ˋ.ˏ;
                        this.ˋ.ˏ(Math.min(4098, Math.max(this.ˎ, obj.length * 2)));
                        System.arraycopy(obj, 0, this.ˋ.ˏ, 0, 3);
                    }
                }
            } else {
                ʽ = Math.min(o_anc.ˊ(), this.ˎ - this.ˏ);
                o_anc.ˎ(this.ˋ.ˏ, this.ˏ, ʽ);
                this.ˏ = ʽ + this.ˏ;
                if (this.ˏ != this.ˎ) {
                    continue;
                } else {
                    if (!this.ॱ) {
                        this.ˋ.ˏ(this.ˎ);
                    } else if (anr.ˎ(this.ˋ.ˏ, 0, this.ˎ, -1) != 0) {
                        this.ʻ = true;
                        return;
                    } else {
                        this.ˋ.ˏ(this.ˎ - 4);
                    }
                    this.ˊ.ˏ(this.ˋ);
                    this.ˏ = 0;
                }
            }
        }
    }
}
